<?php require_once('Connections/locamedicadmin.php'); ?>

<?php include('userValidation.php'); ?>

<?php require_once('functions.php'); ?>

<?php

	$editFormAction = $_SERVER['PHP_SELF'];
	if (isset($_SERVER['QUERY_STRING'])) {
	  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
	}
	
	if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form_update")) {
	  
	  $updateSQL = sprintf("UPDATE csre_text SET value=%s WHERE name=%s",
						   GetSQLValueString($_POST['text_value'], "text"),
						   GetSQLValueString($_POST['page'], "text"));
	
	  mysql_select_db($database_locamedicadmin, $locamedicadmin);
	  $Result1 = mysql_query($updateSQL, $locamedicadmin) or die(mysql_error());
	
	  $updateGoTo = "text_editor.php";
	  header(sprintf("Location: %s", $updateGoTo));
	}


	$colname_texttoedit = "-1";
	if (isset($_POST['page'])) {
	  $colname_texttoedit = (get_magic_quotes_gpc()) ? $_POST['page'] : addslashes($_POST['page']);
	}

	mysql_select_db($database_locamedicadmin, $locamedicadmin);
	$query_texttoedit = sprintf("SELECT name, value FROM csre_text WHERE name = '%s'", $colname_texttoedit);
	$texttoedit = mysql_query($query_texttoedit, $locamedicadmin) or die(mysql_error());
	$row_texttoedit = mysql_fetch_assoc($texttoedit);
	$totalRows_texttoedit = mysql_num_rows($texttoedit);

?>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Locamedic CSRE Admin</title>
<link href="locamedicadmin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
</head>
<body>


<div id="page">

	<?php include('sidebar.php'); ?>
	
	<!-- end sidebar -->
	<div id="content">
		<div align="center"><img src="images/page_image_5.jpg" alt="" /></div>
	  <div class="boxed">
			<h1 class="title2">Text Editor</h1>
			<form action="text_editor.php" method="post" name="combo_form">
			<table>
				<tr valign="baseline">
					<td nowrap>
						Page:
					</td>
					<td>
						<select name="page" onchange="this.form.submit();">
							<option value="-1" <?php if ($colname_texttoedit == -1) { echo "selected=\"selected\"";} ?> >&nbsp;</option>
							<option value="fraisdeservice" <?php if ($colname_texttoedit == "fraisdeservice") { echo "selected=\"selected\"";} ?> >Frais de service</option>
							<option value="demandedinformation" <?php if ($colname_texttoedit == "demandedinformation") { echo "selected=\"selected\"";} ?> >Medipoints</option>
							<option value="index" <?php if ($colname_texttoedit == "index") { echo "selected=\"selected\"";} ?> >Index Page</option>														
						</select>
					</td>
				</tr>
			</table>
			</form>

			<?php if ($colname_texttoedit != -1) { ?>

			<script type="text/javascript" src="tiny_mice.js"></script>

			<form action="text_editor.php" name="form_update" method="post">
				
				<input type="hidden" name="page" value="<?php echo $row_texttoedit['name']; ?>" />
				
				<input type="hidden" name="MM_update" value="form_update" />
				
				<table>
					  <tr>
						<td colspan="2">
						  <textarea name="text_value" style="width:100%; height:200px;"><?php echo $row_texttoedit['value']; ?></textarea>
						</td>
					  </tr>
				</table>
				
				<div class="botonera">
					<input type="submit" value="Save">
				</div>
				
			</form>
			
			<?php } ?>
			
	  </div>
  </div>
	<!-- end content -->
	<div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->

<?php include('footer.php'); ?>

</body>
</html>
<?php
mysql_free_result($texttoedit);
?>